#include "main/utils.h"
using namespace std;

int minTimeDiff(const vector<string> &vec) {
  if (vec.size() > 1440)
    return 0;

  vector<bool> flags(1440, 0);
  for (int i = 0; i < vec.size(); ++i) {
    string minute_str = vec[i].substr(0, 2);
    string second_str = vec[i].substr(3, 2);
    int second = stoi(minute_str) * 60 + stoi(second_str);
    if (flags[second] != 0) {
      return 0;
    } else {
      flags[second] = 1;
    }
  }
  int first_flags = -1;
  int pre_idx = -1;
  int min_diff = INT_MAX;
  for (int i = 0; i < 1440; ++i) {
    if (flags[i] == 1) {
      if (pre_idx != -1 && (i - pre_idx) < min_diff) {
        min_diff = i - pre_idx;
      } else if (pre_idx == -1) {
        first_flags = i;
      }
      pre_idx = i;
    }
  }
  if (first_flags + 1440 - pre_idx < min_diff) {
    min_diff = first_flags + 1440 - pre_idx;
  }
  return min_diff;
}

int main() {
  vector<string> vec = {"23:50", "23:58", "00:05"};
  int ret = minTimeDiff(vec);
  cout << ret << endl;

  return 0;
}
